// mycomponent/Waterfalls_flow.js
var app = getApp();
Page({
  options: {
    styleIsolation: 'shared',
  },
  data:{
    heightauto:'auto',
    widthauto:'auto',
    videoUrl:'',
    videos: [],
    screenHeight: 0,//获取屏幕高度
    statusBarHeight: 0,//获取状态栏高度
    navBarHeight: 0,//获取导航栏高度
    currentIndex: 1,
    current:{},
    allInddex:0,
    isPlay: true,
    allList:[],
    page:1,
    pageSize:5,
    currentIndex:0

  },
  goBack(){
    wx.navigateBack({
      delta: 1  // 返回的页面数，如果 delta 大于现有页面数，则返回到首页。
    });
  },
  slide: function(e) {
    console.log(e)
    const currentIndex  = e.detail.current;
      this.setData({
        videos:[this.data.allList[0],this.data.allList[1],this.data.allList[2]],
        current:this.data.allList[this.data.allInddex]
      })
      this.setData({
        currentIndex:0
      })
      
    console.log(this.data.videos)
  },

  videoPlay: function() {
    let { isPlay } = this.data
    if (isPlay) {
      this.videoContext.pause()
      this.setData({ isPlay: false })
      isPlay = false
    } else {
      this.videoContext.play()
      this.setData({ isPlay: true })
    }
    console.log(this.videoContext, isPlay)
  },


  onLoad(options){
    this.setData({
      videoUrl:options.videoUrl
    })
    this.getInfo()
    this.getVideoList();
  },
  onReady(){
    this.videoContext = wx.createVideoContext('myVideo')
  },
  onShow(){
    
  },
  onHide(){

  },
  onUnload(){

  },
  onPullDownRefresh(){

  },
  onReachBottom(){

  },
  onShareAppMessage(){
    
  },
  getInfo(){
    const res = wx.getSystemInfoSync();
    let windowHeight = res.windowHeight;
    let windowWidth = res.windowWidth;
    this.setData({
      screenHeight: res.screenHeight,
      statusBarHeight: res.statusBarHeight+20,
      navBarHeight: res.system.substring(0, 3) == "iOS" ? 42 : 44,
      heightauto: windowHeight + "px",
      widthauto: windowWidth + "px",
    });
  },
  getVideoList(){
    let that = this
    let urlStr = app.getNetAddresss("plugin.micro-communities.api.index.getStick&resource_type=2");
    //that.data.page = this.data.page + 1;
    //json.page = this.data.page;
    app._postNetWork({
      url: urlStr,
      showToastIn: false,
      //data: json,
      success: function(resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          that.setData({
            allList: JSON.parse(JSON.stringify(res.data.data)),
            videos: res.data.data.splice(that.data.page -1 ,3)
          });
        } 
      },
      fail: function(res) {}
    });
  }
})
